<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        (function fn() {
            let myRandom = Math.floor(Math.random() * 10) + 1
            console.log(myRandom)
            for (let i = 1; i < 9; i++) {
                let myNum = prompt('请输入数字')
                if (+myNum === myRandom) {
                    alert('猜对了')
                    return
                } else {
                    alert('猜错了')
                }
            }
            alert('8次机会已用完')
        }())

    </script>
</body>

</html>